import 'package:flutter/material.dart';
import 'package:im_module/common/GroupCommonType.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_group_member_info.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_group_tips_elem.dart';

///群的一些系统消息 邀请人、退出群...
class GroupTipsMessageWidget extends StatelessWidget {
  final V2TimGroupTipsElem message;

  GroupTipsMessageWidget(this.message);

  @override
  Widget build(BuildContext context) {
    switch (message.type) {
      case GroupCommonType.V2TIM_GROUP_TIPS_TYPE_INVITE:
        //被邀请入群（opMember 邀请 memberList 入群，Work 群有效）
        return Container(
          child:
              returnTips("${message.opMember.nickName}邀请${getNiceNames()}入群"),
        );
      case GroupCommonType.V2TIM_GROUP_TIPS_TYPE_QUIT:
        return returnTips("${message.opMember.nickName}退出群聊");
      case GroupCommonType.V2TIM_GROUP_TIPS_TYPE_GROUP_INFO_CHANGE:
        return returnTips("${message.opMember.nickName}变更聊群资料");
      case GroupCommonType.V2TIM_GROUP_TIPS_TYPE_KICKED:
        //踢出群 (opMember 把 memberList 踢出群组)
        return returnTips(
            "${message.opMember.nickName} 把 ${getNiceNames()}踢出群组");
    }
    return Container();
  }

  Text returnTips(String message) {
    return Text("${message}",
        style: TextStyle(color: Color(0xff999999), fontSize: 14));
  }

  String getNiceNames() {
    String str = '';
    List<V2TimGroupMemberInfo?>? list = message.memberList;
    if (list != null) {
      for (int i = 0; i < list.length; i++) {
        V2TimGroupMemberInfo? value = list[i];
        if (value != null) {
          str += '${value.nickName}';
        }
        if (i + 1 != list.length) {
          str += ',';
        }
      }
    }
    return str;
  }
}
